// 中文、英文、数字、特殊字符
export function filterCENS(val: string): string {
  return val.replace(/[^?!\dA-Za-z\u4E00-\u9FA5~!@#$%^&*()_+-={}[\];':",.<>`]+/g, '')
}

// 中文、英文、数字
export function filterCEN(val: string): string {
  return val.replace(/[^?!\dA-Za-z\u4E00-\u9FA5]+/g, '')
}

// 一位小数（正）
export function filterF1(val: string): string {
  let str = val
    .replace(/[^\d.]/g, '')
    .replace(/^\./g, '')
    .replace(/\.{2,}/g, '.')
    .replace('.', '$#$')
    .replace(/\./g, '')
    .replace('$#$', '.')
    .replace(/^(\-)*(\d+)\.(\d).*$/, '$1$2.$3')
  if (str && str.slice(-1) !== '.') {
    str = parseFloat(str) + ''
  }
  return str
}

// 正整数
export function filterInt(val: string): string {
  let str = val
    .replace(/[^\d.]/g, '')
    .replace(/^\./g, '')
    .replace(/\./g, '')
    .replace(/^(\-)*(\d+)*$/, '$1$2')
  if (str) {
    str = parseInt(str) + ''
  }
  return str
}
